package com.eliza.base.views.learn.text

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableIntStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.font.FontFamily
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.text.style.TextOverflow
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.navigation.NavController
import androidx.navigation.compose.rememberNavController

@Preview
@Composable
private fun asd() {
    TextX.Show(navController = rememberNavController())
}

object TextX {
    @Composable
    fun Show(navController: NavController) {
        Column {
            var count by remember {
                mutableIntStateOf(0)
            }
            Button(onClick = { count = (count + 1) % 8 }) {
                Text(text = "TextX $count")
            }
            when (count) {
                0 -> basic()
                1 -> TextStyleX.Show(navController)
                //使用 Alignment 和 Trim 调整“lineHeight”集合中的文本，并根据需要去除多余的空格
                2 -> UserInteractionsX.Show(navController)
                3 -> FontsX.Show(navController)
                4 -> UserInputX.Show(navController)
                5 -> EmojiX.Show(navController)
            }
        }

    }

    @Composable
    private fun basic() {
        Column {
            Text(
                "Hello World", textAlign = TextAlign.Center,
                modifier = Modifier
                    .width(150.dp)
                    .background(Color.Yellow)
            )
            Text("FontFamily 123", fontFamily = FontFamily.Default)
            Text("FontFamily 123", fontFamily = FontFamily.Cursive)
            Text("FontFamily 123", fontFamily = FontFamily.Serif)

//        限制 Text 可组合项中的可见行数
            Text(
                "maxLines ".repeat(20),
                maxLines = 2,
                color = Color.White,
                modifier = Modifier.background(Color.Blue)
            )
            //文字溢出
            Text(
                "TextOverflow ".repeat(50),
                maxLines = 2,
                overflow = TextOverflow.Ellipsis,
                color = Color.Gray,
                modifier = Modifier.background(Color.Cyan)
            )
        }
    }
}








